home *** CD-ROM | disk | FTP | other *** search
/ Leonardo the Inventor / Leonardo The Inventor (93026)(Broderbund)(Riverdeep)(2004).iso / LEOWINMV / TIMELINE.DIR / 00014_Script_SCROLLBAR SCRIPTS < prev    next >
Text File  |  1996-03-31  |  4KB  |  124 lines

  1.  
  2. on initScrollBar
  3.   global scrollBar,numOfPixelsPerScreen, halfNumPixelsPerScreen,thumb,timeLine,screenWidth
  4.   global numberOfScreens,firstTimeScreenframe, framesBetweenScreens
  5.   
  6.   set scrollBar       = 37 -- TimeBar
  7.   set thumb           = 35
  8.   
  9.   set firstTimeScreenframe = 19
  10.   set framesBetweenScreens = 2
  11.   
  12.   set numberOfScreens = 19
  13.   
  14.   puppetSprite thumb,1
  15.   
  16.   -- the thumb has to be moved numOfPixelsPerScreen pixels to move the timeLine 1 screen
  17.   set scrollBarWidth = the width of sprite scrollBar
  18.   set numOfPixelsPerScreen = (scrollBarWidth * 1.0) / (numberOfScreens - 1)
  19.   set halfNumPixelsPerScreen = numOfPixelsPerScreen/2
  20.   
  21.   -- restrict movement of thumb to the scrollbar
  22.   set the constraint of sprite thumb to scrollBar
  23.   set the moveableSprite of sprite thumb = TRUE
  24. end
  25.  
  26. -------------------------------------------------------------------------------------
  27. -- handler newScreen gets called when clicking on the scrollbar.
  28.  
  29. on newScreen
  30.   global thumb,screenWidth
  31.   
  32.   repeat while the mouseDown
  33.     scroll
  34.   end repeat
  35. end
  36.  
  37. -------------------------------------------------------------------------------------
  38. -- handler newScreenBeforeFirstScreen gets called when clicking on the scrollbar.
  39. -- before the first screen (this is necessary because otherwise the transition doesn't
  40. -- work right).
  41.  
  42. on newScreenFromBeforeFirstScreen
  43.   global firstTimeScreenframe
  44.   
  45.   go firstTimeScreenframe
  46.   newScreen
  47. end
  48.  
  49. -------------------------------------------------------------------------------------
  50. -- handler scrollFromBeforeFirstScreen gets called when dragging the thumb before
  51. -- the first screen (this is necessary because otherwise the transition doesn't
  52. -- work right).
  53.  
  54. on scrollFromBeforeFirstScreen
  55.   global firstTimeScreenframe
  56.   
  57.   go firstTimeScreenframe
  58.   scroll
  59. end
  60.  
  61. -------------------------------------------------------------------------------------
  62. -- handler scroll gets called when dragging the thumb
  63.  
  64. on scroll
  65.   global thumb,scrollBar
  66.   
  67.   repeat while the mouseDown
  68.     set newLocH = the mouseH
  69.     updateLocHOfItem thumb, newLocH
  70.   end repeat  
  71.   
  72.   updateTimeLine
  73. end
  74.  
  75. -------------------------------------------------------------------------------------
  76. -- handler updateTimeLine
  77. --   calculates the new timeline screen from the position of the tumb.
  78. --    shows the new timeline screen
  79. --    calculates the thumbposition that corresponds with the new timeline screen
  80. --    snaps the tumb into this new position
  81.  
  82. on updateTimeLine
  83.   global thumb, framesBetweenScreens, firstTimeScreenframe
  84.   
  85.   set newScreen = getScreenNumFromThumbPos()
  86.   set newFrame = firstTimeScreenframe + (newScreen - 1) * framesBetweenScreens
  87.   
  88.   if newFrame > the frame then 
  89.     goForwardIntime newFrame
  90.   else if newFrame < the frame then 
  91.     goBackIntime newFrame
  92.   end if
  93.   
  94.   -- snap thumb to position
  95.   set newThumbPos = getThumbPosFromScreenNum(newScreen)
  96.   updateLocHOfItem thumb,newThumbPos
  97.   
  98. end
  99.  
  100.  
  101. on getScreenNumFromThumbPos
  102.   global thumb,numOfPixelsPerScreen,halfNumPixelsPerScreen, scrollBar, numberOfScreens
  103.   
  104.   set thumbPos = the locH of sprite thumb - the left of sprite scrollBar
  105.   --  set screenNum = integer((thumbPos+halfNumPixelsPerScreen)  / numOfPixelsPerScreen)
  106.   set screenNum = integer(thumbPos / numOfPixelsPerScreen) + 1
  107.   if screenNum < 1 then set screenNum = 1
  108.   if screenNum > numberOfScreens then set screenNum = numberOfScreens
  109.   return screenNum
  110. end
  111.  
  112.  
  113. on getThumbPosFromScreenNum aScreen
  114.   global numOfPixelsPerScreen,scrollBar
  115.   set newLocH = the left of sprite scrollBar + integer((aScreen-1) * numOfPixelsPerScreen)
  116.   return newLocH
  117. end
  118.  
  119.  
  120. on updateLocHOfItem aSprite, aLocH
  121.   set the locH of sprite aSprite to aLocH
  122.   updateStage
  123. end
  124.